/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package F.Demo.task;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Administrator
 */
public class NoticePanel extends JPanel{
    JPanel pToday =new JPanel();
    JPanel pTomorrow =new JPanel();
    
    JList lst =null;
    
    JTextField txtmsg =new JTextField(30);
    JButton btnok=new JButton("提交");
    
    public NoticePanel(){
        this.setLayout(new GridLayout(2,1,100,5));
        this.add(pToday);
        this.add(pTomorrow);
        
        pToday.setBorder(BorderFactory.createTitledBorder("今日提示"));
        pTomorrow.setBorder(BorderFactory.createTitledBorder("添加明日备忘"));
        
        pToday.setLayout(new BorderLayout());
        pToday.setLayout(new FlowLayout(FlowLayout.CENTER));
        
        this.add(pToday);
        this.add(pTomorrow);
        ArrayList l=new Notices().getTodayNotices();
        if(l==null){
            pToday.add(new JLabel("今天没有什么特别的事情",JLabel.CENTER));
        }else{
            lst=new JList(l.toArray());
            lst.setSize(400,200);
            pToday.add("Center",lst);
        }
        pTomorrow.add(txtmsg);
        pTomorrow.add(btnok);
        btnok.addActionListener(new ActionListener() {                  
            @Override               
            public void actionPerformed(ActionEvent e) {                
                String notice=txtmsg.getText().trim();                
                if(notice.length()==0){                    
                    return;                
                }                
                if(new Notices().setTomorrowNotice(notice)){                    
                    JOptionPane.showConfirmDialog(null,"成功添加一条备忘信息");                    
                    txtmsg.setText("");                
                }                
                else{                    
                    JOptionPane.showMessageDialog(null, "数据添加出现问题");                
                }               
            }           
        });      
    }      
    public void  PaintComponent(Graphics gg){            
    }           
    public static void main(String[] args) {               
        Frame f=new Frame();               
        f.add(new NoticePanel());       
        f.pack();       
        f.show();       
        f.addWindowListener(new WindowAdapter(){        
            @Override
            public void windowClosing(WindowEvent e){                
                System.exit(0);           
            }       
        });   

        
    }

}
